﻿using System;
using System.Configuration;
using System.IO;
using System.Text;

namespace NabNetWeb
{
    public partial class _SendMailXMPP : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string nabSerialNumber = Request.QueryString["sn"];
            string mailDirectory = ConfigurationManager.AppSettings["MailDirectory"];
            if(!Path.IsPathRooted(mailDirectory))
            {
                mailDirectory = Context.Server.MapPath(mailDirectory);
            }

            if(!Directory.Exists(mailDirectory))
            {
                Directory.CreateDirectory(mailDirectory);
            }

            string fileName = nabSerialNumber + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss")+".txt";
            fileName = Path.Combine(mailDirectory, fileName);

            using (FileStream fs = new FileStream(fileName,FileMode.Create))
            {
                byte[] buffer = Encoding.UTF8.GetBytes(Request.Url.ToString());
                fs.Write(buffer, 0, buffer.Length);

                int length = (int)Request.InputStream.Length;
                buffer = new byte[length];
                Request.InputStream.Read(buffer, 0, length);
                fs.Write(buffer,0,length);
            }
        }
    }
}
